package com.irdstudio.efp.esb.api.rest.sed.apply;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.irdstudio.basic.framework.core.constant.BaseConstant;
import com.irdstudio.basic.framework.core.constant.EsbRetCodeStandard;
import com.irdstudio.basic.framework.core.constant.SDicToLocalConstant;
import com.irdstudio.basic.framework.core.exception.BizException;
import com.irdstudio.basic.framework.core.util.*;
import com.irdstudio.basic.framework.core.util.sdic.SDicToLocal;
import com.irdstudio.basic.sequence.service.DefaultPatternDescriptor;
import com.irdstudio.basic.sequence.service.PatternDescriptor;
import com.irdstudio.efp.basic.framework.mq.client.producer.MQProducerMessageClient;
import com.irdstudio.efp.basic.framework.mq.constant.TagEnums;
import com.irdstudio.efp.basic.framework.mq.constant.TopicEnums;
import com.irdstudio.efp.console.common.ConsoleConstant;
import com.irdstudio.efp.console.service.facade.PubSysInfoService;
import com.irdstudio.efp.cus.service.facade.CusIndivService;
import com.irdstudio.efp.cus.service.vo.CusIndivVO;
import com.irdstudio.efp.esb.api.bean.nls.ReqLoanAppBean;
import com.irdstudio.efp.esb.api.common.EsbRespServiceHandler;
import com.irdstudio.efp.esb.api.common.GroupeInterface.sed;
import com.irdstudio.efp.esb.common.constant.MsLoanConstant;
import com.irdstudio.efp.esb.common.constant.nls.NlsTrmTypeEnum;
import com.irdstudio.efp.esb.common.server.req.EsbReqServiceBean;
import com.irdstudio.efp.esb.common.server.resp.EsbRespServiceBean;
import com.irdstudio.efp.limit.service.facade.LmtPrdContService;
import com.irdstudio.efp.limit.service.vo.LmtPrdContVO;
import com.irdstudio.efp.nls.common.constant.NlsApplyInfoEnums;
import com.irdstudio.efp.nls.common.constant.PrdAdaptedSoltEnums;
import com.irdstudio.efp.nls.common.constant.QueueTaskEnums;
import com.irdstudio.efp.nls.service.facade.NlsApplyInfoService;
import com.irdstudio.efp.nls.service.facade.UpdateLmtPrdContService;
import com.irdstudio.efp.nls.service.facade.queue.NlsProcessBizService;
import com.irdstudio.efp.nls.service.facade.sx.NlsCreditInfoService;
import com.irdstudio.efp.nls.service.vo.NlsApplyInfoVO;
import com.irdstudio.efp.nls.service.vo.queue.NlsProcessBizVO;
import com.irdstudio.efp.nls.service.vo.sx.NlsCreditInfoVO;
import org.apache.rocketmq.common.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.Pattern;

import static com.irdstudio.basic.sequence.service.DefaultPatternDescriptor.SEQ;

/**
 * 需求编号：【2019D0519】（业务提的需求编号）
 * 问题编号：【xxxxxxx】（若不是因为修复问题而新增该类，则留空）
 * 开发人员：weijj
 * 创建日期：2019年4月17日 下午8:01:08
 * 功能描述：个人支用申请接口
 */
@RestController
@RequestMapping("/esb")
public class NlsApplySedController {
	private static Logger logger = LoggerFactory.getLogger(NlsApplySedController.class);
	public static final PatternDescriptor PATTERN = DefaultPatternDescriptor.of("S" + SEQ, 9);

	@ModelAttribute("esbReqServiceBean")
	public EsbReqServiceBean getReqEsbHeadBean(HttpServletRequest request) {
		logger.info("校验 ESB请求系统头和请求应用头对象!");
		EsbReqServiceBean esbReqServiceBean = (EsbReqServiceBean) request.getAttribute("esbReqServiceBean");
		return esbReqServiceBean;
	}

	@ModelAttribute("reqLoanAppBean")
	public ReqLoanAppBean getReqEsbBodyBean(HttpServletRequest request) {
		logger.info("校验 ESB请求体对象！");
		String esbReqBody = (String) request.getAttribute("esbReqBody");
		return JSONObject.parseObject(esbReqBody, ReqLoanAppBean.class);
	}

	@PostMapping("/SERVICE_30220001_01_11110001")
	public EsbRespServiceBean doRecv(@Validated @ModelAttribute("esbReqServiceBean") EsbReqServiceBean esbReqServiceBean, BindingResult br1,
                                     @Validated({sed.class}) @ModelAttribute("reqLoanAppBean") ReqLoanAppBean reqLoanAppBean, BindingResult br2, Exception exception) throws Exception {
		String applSeq = reqLoanAppBean.getAppFlowNo();
		String glblSrlNo = esbReqServiceBean.getSysHead().getGlblSrlNo();
		TraceUtil.setTraceId(glblSrlNo);
		logger.info("税e贷个人申请交易开始----------申请流水号：" + applSeq + "------------全局流水号" + glblSrlNo);
		try {
			// 通过切面校验进件申请参数是否正确，如不正确则返回错误信息
			if (Objects.nonNull(exception)) {
				throw exception;
			}

			// 字段校验
			this.checkReqBean(reqLoanAppBean);

			// 判断用信申请流水号是否被使用
			NlsApplyInfoVO nlsApplyInfoVO = new NlsApplyInfoVO();
			nlsApplyInfoVO.setApplySeq(applSeq);
			nlsApplyInfoVO = nlsApplyInfoService.queryByPk(nlsApplyInfoVO);
			if (Objects.nonNull(nlsApplyInfoVO)) {
				throw new Exception("用信申请流水号：" + "【" + applSeq + "】" + "，已经存在用信申请记录，请核查！");
			}

			// 判断客户是否存在在途的支用申请 【目前表示在途的状态有：处理中 01，挂起 05】
			this.checkOnWayApply(reqLoanAppBean.getCertTp(), reqLoanAppBean.getCertNo());

			// 判断全局流水号是否被使用
			this.checkGlobalSerno(glblSrlNo);

			// 根据证件类型与证件号码查询客户信息
			this.checkCust(reqLoanAppBean);

			// 授信信息判断
			NlsCreditInfoVO nlsCreditInfoVO = this.checkCreditInfo(reqLoanAppBean);

			// 授信协议信息判断
			LmtPrdContVO lmtPrdContVO = this.checkLmtPrdCont(reqLoanAppBean);

			// 插入网贷申请基本信息表
			nlsApplyInfoVO = insertNlsApplyInfo(esbReqServiceBean, reqLoanAppBean, nlsCreditInfoVO);

			// 插入网贷业务过程表
			this.insertNlsProcessBiz(applSeq, nlsCreditInfoVO);

			// 更新授信协议信息，预占用额度、可用额度
			this.updLmtPrdCont(lmtPrdContVO, nlsApplyInfoVO);

			// 发送mq，并组装返回报文
			producerService.sendMsg(new Message(TopicEnums.QUEUE_TASK_TOPIC.getTopicId(), TagEnums.TAG_QUEUE_TASK.getTagId(), applSeq,
					JSON.toJSONString(nlsApplyInfoVO).getBytes("UTF-8")));
			return EsbRespServiceHandler.esbSuccessHandler(esbReqServiceBean);

		} catch (BizException e) {
			return EsbRespServiceHandler.esbFailureHandler(esbReqServiceBean, e.getErrorCode(), e.getMessage());
		} catch (Exception e) {
			logger.error("税e贷申请审批服务接口处理失败!" + e.getMessage());
			return EsbRespServiceHandler.esbFailureHandler(esbReqServiceBean, EsbRetCodeStandard.OTHERS_EXCEPTION.getValue(), e.getMessage());
		} finally {
			logger.info("税e贷进件申请交易结束----------申请流水号：" + applSeq + "------------全局流水号" + glblSrlNo);
			TraceUtil.clear();
		}
	}

	private void checkReqBean(ReqLoanAppBean reqLoanAppBean) throws Exception {
		// 支用申请流水号
		String applySeq = reqLoanAppBean.getAppFlowNo();
		// 证件号
		String certNo = reqLoanAppBean.getCertNo();
		// 手机号码
		String mobile = reqLoanAppBean.getMblNo();
		// 期限类型
		String loanTermType = reqLoanAppBean.getLoanTrmType();
		// 贷款申请时间
		String loanReqTime = reqLoanAppBean.getLoanAppTm();
		// 贷款利率
		String loanRate = reqLoanAppBean.getLoanRate();
		// ocr识别失效日期
		String ocrDate = reqLoanAppBean.getOCRIdnfFalDt();

		this.ValidateApplySeq(applySeq);

		if(!NumberUtility.isDouble(loanRate)) {
			throw new BizException(EsbRetCodeStandard.JKYDCSJYBTG.getValue(), "贷款利率【" + loanRate + "输入格式有误！");
		}
		MessageRuleCheckUtil.checkDouble(reqLoanAppBean.getLoanAmt(), "贷款金额", EsbRetCodeStandard.JKYDCSJYBTG.getValue());
		MessageRuleCheckUtil.checkInteger(reqLoanAppBean.getLoanTrm(), "贷款期限", EsbRetCodeStandard.JKYDCSJYBTG.getValue());

		// 身份证
		MessageRuleCheckUtil.validateIdNo18(certNo, EsbRetCodeStandard.KHXXJYBTG.getValue());
		// 手机号
		boolean flag = ValidationUtils.validPhoneNum("0", mobile);
		if (!flag) {
			throw new BizException(EsbRetCodeStandard.KHXXJYBTG.getValue(), "手机号码格式错误");
		}

		MessageRuleCheckUtil.checkDate("贷款申请时间", loanReqTime, "HH:mm:ss", EsbRetCodeStandard.JKYDCSJYBTG.getValue());
		if(StringUtil.isStrNotEmpty(ocrDate)) {
			MessageRuleCheckUtil.checkDate("ocr识别失效日期", ocrDate, "yyyy-MM-dd", EsbRetCodeStandard.JKYDCSJYBTG.getValue());
		}

		if(!NlsTrmTypeEnum.Y.getValue().equals(loanTermType)) {
			throw new BizException(EsbRetCodeStandard.JKYDCSJYBTG.getValue(), "贷款期限类型只能为“年”！");
		}
	}

	/**
	 * 校验支用申请流水号是否满足规则：YX+yyyyMMddHHmmss+seq(6位)
	 */
	private void ValidateApplySeq(String applySeq) throws BizException {
		if(!MessageRuleCheckUtil.checkDate(applySeq.substring(2, 16)).matches()) {
			throw new BizException(EsbRetCodeStandard.JKYDCSJYBTG.getValue(), "支用申请流水号格式不正确！");
		}
		String regex = "YX" +"[0-9]{20}";
		Pattern pattern = Pattern.compile(regex);
		if (!pattern.matcher(applySeq).matches()) {
			throw new BizException(EsbRetCodeStandard.JKYDCSJYBTG.getValue(), "支用申请流水号格式不正确！");
		}
	}

	/**
	 * 判断客户是否存在在途的支用申请
	 */
	private void checkOnWayApply(String certType, String certCode) throws BizException {
		NlsApplyInfoVO nlsApplyInfoVO = new NlsApplyInfoVO();
		nlsApplyInfoVO.setCertType(certType);
		nlsApplyInfoVO.setCertCode(certCode);
		int num = nlsApplyInfoService.countCustHasUsingLetter(nlsApplyInfoVO);
		if(num > 1) {
			throw new BizException(EsbRetCodeStandard.WFJKYWGZ.getValue(), "证件号码为："+nlsApplyInfoVO.getCertCode()+ "的客户，存在其他在途的用信申请信息！");
		}
	}

	/**
	 * 根据全局流水号统计支用申请信息
	 */
	private int checkGlobalSerno(String globalSerno) {
		return nlsApplyInfoService.countInfosByGlobalSerno(globalSerno);
	}

	/**
	 * 客户信息判断
	 */
	private void checkCust(ReqLoanAppBean reqLoanAppBean) throws BizException {
		String certCode = reqLoanAppBean.getCertNo();
		String certType = reqLoanAppBean.getCertTp();
		String cusName = reqLoanAppBean.getBrwNm();

		CusIndivVO cusIndivVO = new CusIndivVO();
		cusIndivVO.setCertCode(certCode);
		cusIndivVO.setCertType(certType);
		cusIndivVO = cusIndivService.queryContractEle(cusIndivVO);
		if(Objects.isNull(cusIndivVO)) {
			throw new BizException(EsbRetCodeStandard.KHXXJYBTG.getValue(), "根据证件类型编号【" + certType + "】，证件号码【" + certCode +"】，查询到的客户信息为空！");
		}
		if(!cusName.equals(cusIndivVO.getCusName())) {
			throw new BizException(EsbRetCodeStandard.KHXXJYBTG.getValue(), "借款人姓名【" + cusName + "】，与客户信息表中客户姓名【" + cusIndivVO.getCusName() + "】，不一致！");
		}
	}

	/**
	 * 授信信息判断
	 */
	private NlsCreditInfoVO checkCreditInfo(ReqLoanAppBean reqLoanAppBean) throws BizException {
		String lmtApplySeq = reqLoanAppBean.getCrdtAppFlowNo();
		NlsCreditInfoVO nlsCreditInfoVO = new NlsCreditInfoVO();
		nlsCreditInfoVO.setLmtApplySeq(lmtApplySeq);
		nlsCreditInfoVO.setCertCode(reqLoanAppBean.getCertNo());
		nlsCreditInfoVO.setCertType(reqLoanAppBean.getCertTp());
		nlsCreditInfoVO = nlsCreditInfoService.queryByCondition(nlsCreditInfoVO);

		if (Objects.isNull(nlsCreditInfoVO) || StringUtil.isNullorBank(nlsCreditInfoVO.getLmtApplySeq())) {
			throw new BizException(EsbRetCodeStandard.WFJKYWGZ.getValue(), "授信申请流水号【 " + lmtApplySeq + "】，不存在授信数据!");
		}
		if(!NlsApplyInfoEnums.NlsApplyState.PASS.getKey().equals(nlsCreditInfoVO.getApprvSts())) {
			throw new BizException(EsbRetCodeStandard.WFJKYWGZ.getValue(), "授信申请审批不是通过状态！");
		}
		if(!reqLoanAppBean.getProdCd().equals(nlsCreditInfoVO.getPrdCode()) || !reqLoanAppBean.getLoanProdNm().equals(nlsCreditInfoVO.getPrdName())) {
			throw new BizException(EsbRetCodeStandard.WFJKYWGZ.getValue(), "用信与授信产品不一致!");
		}
		return nlsCreditInfoVO;
	}

	/**
	 * 授信协议信息判断
	 */
	private LmtPrdContVO checkLmtPrdCont(ReqLoanAppBean reqLoanAppBean) throws BizException {
		//支用申请流水号
		String lmtApplySeq = reqLoanAppBean.getAppFlowNo();
		//贷款金额
		BigDecimal loanAmt = new BigDecimal(reqLoanAppBean.getLoanAmt());
		LmtPrdContVO lmtPrdContVO = lmtPrdContService.qryLmtPrdContByLmtApplySeq(lmtApplySeq);
		if(Objects.isNull(lmtPrdContVO)) {
			throw new BizException(EsbRetCodeStandard.WFJKYWGZ.getValue(), "通过授信申请流水号【" + lmtApplySeq + "】，获取的授信协议信息为空！");
		}
		if(!ConsoleConstant.LIMIT_STS_02.equals(lmtPrdContVO.getLmtStatus())) {
			throw new BizException(EsbRetCodeStandard.WFJKYWGZ.getValue(), "通过授信申请流水号【" + lmtApplySeq + "】，获取的授信额度状态不是有效的！");
		}
		BigDecimal availAmt = null == lmtPrdContVO.getAvailAmt() ? BigDecimal.ZERO : lmtPrdContVO.getAvailAmt();
		if(loanAmt.compareTo(availAmt) == 1) {
			throw new BizException(EsbRetCodeStandard.WFJKYWGZ.getValue(), "支用申请额度【" +loanAmt+ "】大于授信可用额度【"+availAmt+"】，支用申请失败！");
		}
		return lmtPrdContVO;
	}

	/***
	 * 插入网贷申请基本信息
	 */
	private NlsApplyInfoVO insertNlsApplyInfo(EsbReqServiceBean esbReqServiceBean, ReqLoanAppBean reqLoanAppBean, NlsCreditInfoVO nlsCreditInfoVO) throws Exception {
		NlsApplyInfoVO nlsApplyInfoVO = new NlsApplyInfoVO();
		/************************************************ 网贷申请基本信息表数据来源于【渠道端】字段  ********************************************** start */
		// 流水号
		nlsApplyInfoVO.setApplySeq(reqLoanAppBean.getAppFlowNo());
		// 客户名称
		nlsApplyInfoVO.setCusName(reqLoanAppBean.getBrwNm());
		// 证件类型
		nlsApplyInfoVO.setCertType(SDicToLocal.getLocalSysDicVal(SDicToLocalConstant.CERT_TYPE_SED, reqLoanAppBean.getCertTp()));
		// 证件号码
		nlsApplyInfoVO.setCertCode(reqLoanAppBean.getCertNo());
		// 证件到期日
		nlsApplyInfoVO.setIndivIdExpDt(reqLoanAppBean.getCertMatureDt());
		// 手机号码
		nlsApplyInfoVO.setMobile(reqLoanAppBean.getMblNo());
		// 申请时间
		nlsApplyInfoVO.setApplyTime(reqLoanAppBean.getLoanAppTm());
		// 贷款金额
		nlsApplyInfoVO.setApplyAmt(new BigDecimal(reqLoanAppBean.getLoanAmt()));
		// 贷款期限
		nlsApplyInfoVO.setLoanTerm(reqLoanAppBean.getLoanTrm());
		// 期限类型
		nlsApplyInfoVO.setLoanTermType(SDicToLocal.getLocalSysDicVal(SDicToLocalConstant.TERM_TYPE, reqLoanAppBean.getLoanTrmType()));
		//借款用途
		nlsApplyInfoVO.setLoanPurpose(reqLoanAppBean.getBrwUsg());
		// 产品id
		nlsApplyInfoVO.setPrdId(reqLoanAppBean.getProdCd());
		// 产品代码
		nlsApplyInfoVO.setPrdCode(reqLoanAppBean.getProdCd());
		// 产品名称
		nlsApplyInfoVO.setPrdName(reqLoanAppBean.getLoanProdNm());
		// 币种
		nlsApplyInfoVO.setLoanCcy(SDicToLocal.getLocalSysDicVal(SDicToLocalConstant.CURRENCY, reqLoanAppBean.getCurrCd()));
		// 贷款利率
		nlsApplyInfoVO.setLoanRate(new BigDecimal(reqLoanAppBean.getLoanRate()));
		// 还款方式
		nlsApplyInfoVO.setRepayMethod(SDicToLocal.getLocalSysDicVal(SDicToLocalConstant.REPAY_WAY, reqLoanAppBean.getRpyMd()));
		// 渠道
		nlsApplyInfoVO.setChannelNo(reqLoanAppBean.getChanFlg());
		// 授信流水号
		nlsApplyInfoVO.setLmtApplySeq(reqLoanAppBean.getCrdtAppFlowNo());
		// 全局流水号
		nlsApplyInfoVO.setGlobalSerno(esbReqServiceBean.getSysHead().getGlblSrlNo());
		// 平台ID
		nlsApplyInfoVO.setPlatfmId(esbReqServiceBean.getSysHead().getPlafmID());
		// 平台用户ID
		nlsApplyInfoVO.setPlatfmUsrID(esbReqServiceBean.getSysHead().getPlafmUsrID());
		/************************************************ 网贷申请基本信息表数据来源于【渠道端】字段  ********************************************** end   */


		/**------------------- 网贷申请基本信息表数据来源于【本地授信申请信息表】字段 --------------- start */
		// 客户id
		nlsApplyInfoVO.setCusId(nlsCreditInfoVO.getCusId());
		//网贷经办人
		nlsApplyInfoVO.setNlsOperUserid(nlsCreditInfoVO.getNlsOperUserid());
		//网贷经办机构
		nlsApplyInfoVO.setNlsOperOrgid(nlsCreditInfoVO.getNlsOperOrgid());
		// 放款卡号
		nlsApplyInfoVO.setDnAccount(nlsCreditInfoVO.getDnAccount());
		// 还款卡号
		nlsApplyInfoVO.setRecvAcctNo(nlsCreditInfoVO.getRecvAccount());
		/**------------------- 网贷申请基本信息表数据来源于【本地授信申请信息表】字段 --------------- end   */

		/*********  网贷申请基本信息表数据来源于【其他】************ start */
		// 申请日期  = 营业日期
		nlsApplyInfoVO.setApplyDate(pubSysInfoService.getOpenday(BaseConstant.SYS_ID_1001));
		// 网贷申请状态---处理中
		nlsApplyInfoVO.setNlsApplyState(MsLoanConstant.NlsApplyStateEnum.APPR.VALUE);
		// 放款状态  = 待放款
		nlsApplyInfoVO.setDnSts(BaseConstant.DN_STS_3);
		// 用信插槽阶段
		nlsApplyInfoVO.setSoltStage(PrdAdaptedSoltEnums.SoltStageEnum.LETTER.getVALUE());
		// 创建人（直接插值）
		nlsApplyInfoVO.setCreateUser(BaseConstant.ADMIN);
		// 创建时间
		nlsApplyInfoVO.setCreateTime(DateUtility.getCurrAppDateTimeString());
		// 最后修改人（ 直接插值）
		nlsApplyInfoVO.setLastModifyUser(BaseConstant.ADMIN);
		// 最后修改时间
		nlsApplyInfoVO.setLastModifyTime(DateUtility.getCurrAppDateTimeString());
		/*********  网贷申请基本信息表数据来源于【其他】************ end   */

		int result = nlsApplyInfoService.insertNlsApplyInfo(nlsApplyInfoVO);
		if (result != 1){
			throw new BizException(EsbRetCodeStandard.YWLJCLYC.getValue(), "插入用心申请信息失败！");
		}
		return nlsApplyInfoVO;
	}

	/**
	 * 更新额度协议信息，预占用额度、可用额度
	 */
	private void updLmtPrdCont(LmtPrdContVO lmtPrdContVO, NlsApplyInfoVO nlsApplyInfoVO) throws BizException {
		String lmtApplySeq = nlsApplyInfoVO.getLmtApplySeq();
		// 支用申请金额
		BigDecimal loanAmt = nlsApplyInfoVO.getApplyAmt();
		// 通过授信申请流水号获取除了自身外的所有支用申请流水号集
		List<String> applySeqs = updateLmtPrdContService.getApplySeqList(lmtApplySeq);
		// 获取授信额度
		BigDecimal lmtAmt = Optional.ofNullable(lmtPrdContVO.getLmtAmt()).orElse(BigDecimal.ZERO);
		// 获取预占用额度
		BigDecimal preOccAmt = Optional.ofNullable(updateLmtPrdContService.getPreOccAmt(lmtApplySeq)).orElse(BigDecimal.ZERO);
		// 获取已用额度
		BigDecimal occAmt = Optional.ofNullable(updateLmtPrdContService.getOccAmt(applySeqs)).orElse(BigDecimal.ZERO);

		// 更新预占用额度 = 原预占用  + 支用申请金额
		lmtPrdContVO.setPreOccAmt(preOccAmt.add(loanAmt));
		// 更新可用额度 = 授信额度 - 支用申请金额 - 原预占用额度 - 已用额度
		lmtPrdContVO.setAvailAmt(lmtAmt.subtract(loanAmt).subtract(preOccAmt).subtract(occAmt));
		int num = lmtPrdContService.updateByPk(lmtPrdContVO);
		if(num < 0) {
			throw new BizException(EsbRetCodeStandard.SJCLYC.getValue(), "更新授信协议表预占用额度、可用额度失败！");
		}	
	}

	/**
	 * 初始化网贷业务过程信息表
	 */
	private void insertNlsProcessBiz(String applSeq, NlsCreditInfoVO nlsCreditInfoVO) throws BizException {
		NlsProcessBizVO inNlsProcessBizVo = new NlsProcessBizVO();
		// 申请流水号
		inNlsProcessBizVo.setApplySeq(applSeq);
		// 客户编号
		inNlsProcessBizVo.setCusId(nlsCreditInfoVO.getCusId());
		// 客户名称
		inNlsProcessBizVo.setCusName(nlsCreditInfoVO.getCusName());
		// 产品ID
		inNlsProcessBizVo.setPrdId(nlsCreditInfoVO.getPrdId());
		// 产品代码
		inNlsProcessBizVo.setPrdCode(nlsCreditInfoVO.getPrdId());
		inNlsProcessBizVo.setPrdName(nlsCreditInfoVO.getPrdName());// 产品名称
		inNlsProcessBizVo.setHangTimes(QueueTaskEnums.QueueHangTimesEnum.INITIALIZE.getTimes());
		inNlsProcessBizVo.setQueueTaskState(QueueTaskEnums.QueueTaskStateEnum.EXECUTORY.getCode());
		// 创建时间
		inNlsProcessBizVo.setCreateTime(DateUtility.getCurrAppDateTimeString());
		// 最后修改时间
		inNlsProcessBizVo.setLastModifyTime(DateUtility.getCurrAppDateTimeString());
		// 创建日期
		inNlsProcessBizVo.setCreateDate(DateUtility.getCurrAppDateStr());
		int num = nlsProcessBizService.insertNlsProcessBiz(inNlsProcessBizVo);
		if(num < 0) {
			throw new BizException(EsbRetCodeStandard.SJCLYC.getValue(), "插入数据表异常!");
		}
	}


	@Autowired
	@Qualifier("nlsApplyInfoService")
	private NlsApplyInfoService nlsApplyInfoService;
	@Autowired
	@Qualifier("nlsProcessBizService")
	private NlsProcessBizService nlsProcessBizService;
	@Autowired
	@Qualifier("pubSysInfoService")
	private PubSysInfoService pubSysInfoService;
	@Autowired
	@Qualifier("cusIndivService")
	private CusIndivService cusIndivService;
	@Autowired
	@Qualifier("nlsCreditInfoService")
	private NlsCreditInfoService nlsCreditInfoService;
	@Autowired
	@Qualifier("lmtPrdContService")
	private LmtPrdContService lmtPrdContService;
	@Autowired
	@Qualifier("producerService")
	private MQProducerMessageClient producerService;
	@Autowired
	@Qualifier("updateLmtPrdContService")
	private UpdateLmtPrdContService updateLmtPrdContService;

}
